package de.hska.algo.labor2010.strecken;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.util.ArrayList;

public class MyImage {
	private BufferedImage img;
	public BufferedImage getIMG(){return img;}
	
	MyImage(int dim){
		img = new BufferedImage(dim, dim, BufferedImage.TYPE_INT_ARGB);
		Graphics2D g = img.createGraphics();
		g.setBackground(Color.WHITE);
		g.fillRect(0, 0, img.getWidth(), img.getHeight());
	}
	public void drawGrid(ArrayList<GridPart> grid,boolean fill){
	Graphics2D g = img.createGraphics();
	g.setColor(Color.GREEN);
	g.setStroke(new BasicStroke(1));
	for (GridPart part : grid) {
		g.drawRect((int) (part.getLowerLeft().getX() ), (int) (part
				.getLowerLeft().getY() ), (int) ((part.getUpperRight()
				.getX() - part.getLowerLeft().getX())), (int) ((part
				.getUpperRight().getY() - part.getLowerLeft().getY())));
		if(part.getLines().size()== 1 && fill){
			g.setColor(Color.BLUE);
			g.fillRect((int) (part.getLowerLeft().getX() ), (int) (part
				.getLowerLeft().getY() ), (int) ((part.getUpperRight()
				.getX() - part.getLowerLeft().getX())), (int) ((part
				.getUpperRight().getY() - part.getLowerLeft().getY())));
		
		}
		if(part.getLines().size()> 1 && fill){
			g.setColor(Color.YELLOW);
			g.fillRect((int) (part.getLowerLeft().getX() ), (int) (part
				.getLowerLeft().getY() ), (int) ((part.getUpperRight()
				.getX() - part.getLowerLeft().getX())), (int) ((part
				.getUpperRight().getY() - part.getLowerLeft().getY())));
		
		}

	}
	}
	public void drawLines(ArrayList<Line> lines){
		Graphics2D g = img.createGraphics();
		g.setColor(Color.BLACK);
		BasicStroke bs = new BasicStroke(2);
		g.setStroke(bs);
		for (Line aLine : lines) {
			g.drawLine((int) aLine.getP1().getX()  , (int) aLine.getP1()
					.getY() , (int) aLine.getP2().getX() , (int) aLine
					.getP2().getY() );
		}
		
	}
	public void drawPoints(ArrayList<Point> intersections){
		for (int i = 0; i < intersections.size(); i++){
			//System.out.println(intersections.get(i));
			Graphics2D g = img.createGraphics();
		
			g.setColor(Color.RED);
			 g.setStroke(new BasicStroke(1));
			 g.drawRect((int) (intersections.get(i).getX() ), (int) (intersections.get(i).getY() ), 2, 2);
			 
		}
		
	}

}
